﻿using System;
using System.IO;

class ReplaceWholeWords
{
    static void Main()
    {
        //Exercise 8.
        //Modify the solution of the previous problem to replace only whole words (not substrings).

        StreamReader reader = new StreamReader(@"C:\Users\Toni\Desktop\Test Replace.txt");
        StreamWriter writer = new StreamWriter(@"C:\Users\Toni\Desktop\Test Replace Result.txt");

        try
        {
            string line = reader.ReadLine();
            while (line != null)
            {
                string[] replacedString = line.Split(' ');
                   
                for (int i = 0; i < replacedString.Length; i++)
                {
                    if (replacedString[i] == "start")
                    {
                        writer.Write("finish");
                    }
                    else
                    {
                        writer.Write(replacedString[i]);
                    }
                    writer.Write(' ');
                }
                writer.WriteLine();
                line = reader.ReadLine();
            }
        }
        finally
        {
            reader.Close();
            writer.Close();
        }
    }
}

